let baseOption = {
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: [
        {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
                alignWithLabel: true
            }
        }
    ],
    yAxis: [
        {
            type: 'value'
        }
    ],
    series: [
        {
            name: 'Direct',
            type: 'bar',
            barWidth: '60%',
            data: [10, 52, 200, 334, 390, 330, 220]
        }
    ]
};

function setXAxis(years) {
  baseOption.xAxis[0].data = Array.from(years);
}

export function buildBaseBar(data) {

  let years = new Set()
  let roes = new Map()

  data.forEach(element => {
    let year = element.ses.substring(0, 4);
    years.add(year);
    let roe = roes.get(year) || 0;
    roe = roe + element.roe;
    roes.set(year, roe);
  })

  setXAxis(years);
  baseOption.series[0].name = 'ROE';
  baseOption.series[0].data = Array.from(roes.values());

  return baseOption;
}